package com.come4loves.game.module.actor.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;

import com.come4loves.game.dbproxy.entity.Actor;
import com.come4loves.game.dbproxy.entity.UidActorID;
import com.come4loves.game.module.actor.dao.ActorDao;
import com.come4loves.game.module.actor.dao.UidActorIdDao;
import com.come4loves.game.module.actor.service.ActorService;
@Component
public class ActorServiceImpl implements ActorService {
	@Autowired
	private ActorDao actorDao;
	
	@Autowired
	@Qualifier("game.server.id")
	private int serverId;
	
	@Autowired
	private UidActorIdDao uidActorIdDao;
	@Override
	public Actor getActor(long actorId) {
		return actorDao.getActor(actorId);
		
	}
	
	@Override
	public boolean isExsitActor(String uid) {
		UidActorID u = uidActorIdDao.getUidActorID(uid);
		return u.getActorId() > 0;
	}
	
	@Override
	public long createActor() {
		return actorDao.createActor(serverId);
	}
	
	@Override
	public long getActorId(String uid) {
		UidActorID u = uidActorIdDao.getUidActorID(uid);
		return u.getActorId();
	}
	
	@Override
	public boolean uidBindActor(String uid, long actorId) {
		boolean flag = actorDao.exsit(actorId);
		if (flag){
			UidActorID u = uidActorIdDao.getUidActorID(uid);
			Actor actor = actorDao.getActor(actorId);
			u.setActorId(actor.getPkId());
			uidActorIdDao.updateUidActorID(u);
			return true;
		}
		return false;
	}
	

}
